package com.zeta.eduservice.controller.question;


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zeta.base.BaseController;
import com.zeta.commonutils.R;
import com.zeta.eduservice.entity.EduTeacher;
import com.zeta.eduservice.entity.question.ChapterAQuestionTypeSysAndChoicequestion;
import com.zeta.eduservice.entity.question.EduChapterAndQuestionTypeSys;
import com.zeta.eduservice.entity.question.EduQuestion;
import com.zeta.eduservice.entity.question.EduQuestionChoice;
import com.zeta.eduservice.entity.vo.QuestionChoiceVo;
import com.zeta.eduservice.entity.vo.QuestionQuery;
import com.zeta.eduservice.entity.vo.QuestionUploadVo;
import com.zeta.eduservice.entity.vo.TeacherQuery;
import com.zeta.eduservice.entity.vo.questionVo;
import com.zeta.eduservice.service.ChapterAQuestionTypeSysAndChoicequestionService;
import com.zeta.eduservice.service.EduChapterAndQuestionTypeSysService;
import com.zeta.eduservice.service.EduCourseService;
import com.zeta.eduservice.service.EduQuestionChoiceService;

/**
 * <p>
 * 选择试题 前端控制器
 * </p>
 *
 * @author zeta
 * @since 2020-10-08
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/edu_question_choice")
public class EduQuestionChoiceController extends BaseController<EduQuestionChoice>{
	@Override
	public IService<EduQuestionChoice> getBaseService() {
		// TODO Auto-generated method stub
		return choiceService;
	}
	@Autowired
	private ChapterAQuestionTypeSysAndChoicequestionService chapterAQuestionTypeSysAndChoicequestionService; 

	@Autowired
	private EduChapterAndQuestionTypeSysService chapterAndQuestionTypeSysService; 

	@Autowired
	private EduQuestionChoiceService choiceService;
	@PostMapping("retId")
	public R add(@RequestBody EduQuestionChoice object) {
		choiceService.save(object);
		return R.ok().data("id",object.getId());
	}
	@DeleteMapping("{id}")
	public R delete(@PathVariable String id) {
		choiceService.removeById(id);
		return R.ok();
	}
	@PostMapping("upload")
	public void uploadQuestion(MultipartFile file,QuestionUploadVo QuestionUploadVo) throws IOException {
		choiceService.upload(file,QuestionUploadVo,choiceService,chapterAQuestionTypeSysAndChoicequestionService);
	}
	@PostMapping("page/{current}/{limit}")
	public R GetQuestionsByQuestionTypeMidid(@PathVariable long current, @PathVariable long limit,@RequestBody(required = false) QuestionQuery searchObj) {
		Page<QuestionChoiceVo> page = new Page<>(current, limit);
		List<QuestionChoiceVo> byclass = choiceService.getsByMidId(page,searchObj);
		long total = page.getTotal();
		return R.ok().data("total", total).data("list", byclass);

	}
	@PostMapping("pageByPaper/{current}/{limit}")
	public R getByPaperTypeId(@PathVariable long current, @PathVariable long limit,@RequestBody(required = false) QuestionQuery searchObj) {
	
		
		Page<QuestionChoiceVo> page = new Page<>(current, limit);
		List<QuestionChoiceVo> byclass = choiceService.getByPaperTypeId(page,searchObj);
		long total = page.getTotal();
		return R.ok().data("total", total).data("list", byclass);

	}
	@PostMapping("pageByTypeAndCourse/{current}/{limit}")
	public R GetQuestionsByQuestionTypeSys(@PathVariable long current, @PathVariable long limit,@RequestBody(required = false) QuestionQuery searchObj) {
		
		Page<QuestionChoiceVo> page = new Page<>(current, limit);
		List<QuestionChoiceVo> byclass = choiceService.getsByCourseIdAndTypeSys(page,searchObj);
		long total = page.getTotal();
		return R.ok().data("total", total).data("list", byclass);

	}
	
	
}

